package org.cy.evolution.framework.ui;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;

public abstract class BaseFragment extends Fragment {

    private boolean isLoaded = false;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        isLoaded = true;
        if (isLoaded && getUserVisibleHint()) {
            lazyLoad();
            isLoaded = false;
        }

    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (!isLoaded && isVisibleToUser) {
            lazyLoad();
            isLoaded = false;
        }
    }

    public abstract void lazyLoad();
}
